<?php
$isReloadable = false;
require_once("../../pers/inc.config.php");
require_once(R2_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(R2_FS_WEB_ROOT.'/app/_inc/funct.html.php');
require R2_FS_WEB_ROOT.'/app/_inc/inc.aTipiRint.php';

//Gestione azioni
if (reqvar('azione')=='registra'){$msgPag .= azioneRegistra();}

foreach($aTipiRint as $kX => $aCX) {
	reqDef('ident_'.$kX,$kX);
	reqDef('descr_'.$kX,$aCX['des']);
	reqDef('desbr_'.$kX,$aCX['desBreve']);
}
for($k=1;$k<11;$k++) {
	reqDef('ident_'.$k,$k);
	reqDef('descr_'.$k,'');
	reqDef('desbr_'.$k,'');
}
$sCmdL = "";
$sCmdR = "";

if ($objSess->abilitaz['gescomm'] == 'W') {
	$sCmdR .= "<a class='cmd1' href='javascript:document.frm1.submit();' >registra</a>";
}	
$sCmdR .= cmdTorna('torna');

$aMenuPag = array();
include("_inc/inc.aMenuPag.php");
testaHtml('Modifica Tipi Rint', $msgPag, '30.10.10', $aMenuPag);
echo getHtmlForm('frm1');
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('azione','registra');

foreach ($aStatiRint as $kX => $aX) {
	$aStatiFin[$kX] = $kX." - ".$aX['descr'];
}
?>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='top'><?=$sCmdL?></td>
      <td class="cmd1" align="right"><?=$sCmdR?></td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<tr>
		<td class="tit1" colspan='3' align='center'>Tipi Richiesta Intervento</td>
	</tr>
    <tr>
   	<td class="lab1" width='20' align='center'>id</td>
  	  	<td class="lab1" width='300'align='left'>&nbsp;&nbsp;&nbsp;Descrizione</td>
	  	<td class="lab1" align='left'>&nbsp;&nbsp;&nbsp;Descrizione breve</td>
    </tr>
<?php 
for($k=1;$k<11;$k++) {
?>
    <tr>
   	<td class="txt1" align='right'>
   		<?php echo getHtmlHidden('ident_'.$k); echo reqVar('ident_'.$k);?>&nbsp;
		</td>
   	<td class="txt1" align='left'>
   		&nbsp;&nbsp;&nbsp;<?php echo getHtmlText('descr_'.$k,50); ?>
		</td>
   	<td class="txt1" align='left'>
   		&nbsp;&nbsp;&nbsp;<?php echo getHtmlText('desbr_'.$k,50); ?>
		</td>
	</tr>
<?php 
}
?>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='top'><?=$sCmdL?></td>
      <td class="cmd1" align="right"><?=$sCmdR?></td>
   </tr>
</table>
<?
codaHtml();
exit();

function azioneRegistra() {
	global $objDB, $objSess;

	$msg = '';
	for($nn=1;$nn<11;$nn++) {
		if (reqVarTrim('descr_'.$nn)!='') continue;
		$sSql = "SELECT id_rint FROM rint WHERE tipo_rint = ".reqVarInt('ident_'.$nn);
		$objDB->exec($sSql);
		if ($aX=$objDB->fetch()) {
			$msg .= "tipo rint '".reqVar('ident_'.$nn)."' utilizzato - non cancellabile !<br>";
		}
	}
	if ($msg!="") return $msg;
	$sSql = "DELETE FROM parametro WHERE id_utente = 0 AND sezione = 'tipiRint'";
	$objDB->exec($sSql);
	
	for($nn=1;$nn<11;$nn++) {
		if (reqVarTrim('descr_'.$nn)=='') continue;
		if (reqVarTrim('desbr_'.$nn)=='') $_REQUEST['desbr_'.$nn] = reqVarTrim('descr_'.$nn);
		$sSql = "INSERT INTO parametro SET  id_utente = 0, sezione = 'tipiRint' "
			.", codice = ".reqVarInt('ident_'.$nn)
			.", descr = '".reqVarAS('descr_'.$nn)."'"
			.", valore = '".reqVarAS('desbr_'.$nn)."'";
		$objDB->exec($sSql);
	}
		
	header("Location: ".urlTorna());
	exit();
}
